package com.guiji.quartz.mapper;

import cn.hutool.core.date.DateTime;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.guiji.quartz.domain.SpiderNews;
import com.guiji.common.core.mybatisplus.core.BaseMapperPlus;
import com.guiji.common.core.mybatisplus.cache.MybatisPlusRedisCache;
import com.guiji.quartz.vo.SpiderNewsStat;
import com.guiji.quartz.vo.SpiderNewsStatAddBo;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * newsMapper接口
 *
 * @author ruoyi
 * @date 2021-07-14
 */
// 如使需切换数据源 请勿使用缓存 会造成数据不一致现象
//@CacheNamespace(implementation = MybatisPlusRedisCache.class, eviction = MybatisPlusRedisCache.class)
@DS("slave")
public interface SpiderNewsMapper extends BaseMapperPlus<SpiderNews> {
	@Select("SELECT COUNT(*) news_count,news_category FROM spider_news WHERE create_time>#{t2} AND create_time<#{t1} GROUP BY news_category")
	List<SpiderNewsStat> selectHourNews(@Param("t1")DateTime t1, @Param("t2")DateTime t2);

	@Select("SELECT COUNT(*) news_count,news_category FROM spider_news WHERE create_time LIKE concat(#{t}, '%') GROUP BY news_category")
	List<Map<String,String>> countDownload(@Param("t")String t);
}
